package edu.hitsz.shootStrategy;

import edu.hitsz.aircraft.AbstractAircraft;
import edu.hitsz.aircraft.HeroAircraft;
import edu.hitsz.bullet.BaseBullet;
import edu.hitsz.bullet.EnemyBullet;
import edu.hitsz.bullet.HeroBullet;

import javax.net.ssl.HandshakeCompletedListener;
import java.util.LinkedList;
import java.util.List;

public class ShootRing implements ShootStrategy{
    @Override
    public List<BaseBullet> doShoot(AbstractAircraft abstractAircraft) {
        List<BaseBullet> res = new LinkedList<>();

        double speedAbs=5;
        double radius=80;

        int shootNum=20;
        double angleIncrement=2*Math.PI/shootNum;

        double angle = 0;

        for(int i = 0; i<shootNum; i++){
            // 多个子弹横向分散
            angle+=angleIncrement;

            int x = (int) (abstractAircraft.getLocationX() + Math.cos(angle) * radius);
            int y = (int) (abstractAircraft.getLocationY() + Math.sin(angle) * radius);

            int speedX = (int) (Math.cos(angle) * speedAbs);
            int speedY = (int) (Math.sin(angle) * speedAbs);
            BaseBullet bullet;
            if(abstractAircraft instanceof HeroAircraft) {
                bullet = new HeroBullet(x, y, speedX, speedY, abstractAircraft.getPower());
            }else {
                bullet = new EnemyBullet(x, y, speedX, speedY, abstractAircraft.getPower());
            }
            res.add(bullet);
        }
        return res;
    }
}
